#include "stdafx.h"
#include "./tmAnimation.h"

float v[10] = {10,9,8,7,6,5,4,3,2,1};

VOID tmSlidingAnim::onInput( int x,InputType type )
{
	if(type == MouseDn )
	{
		_state = Pressed;
		return onPressed(x);
	}
	else if(type == MouseMv )
	{
		if(_state == Pressed || _state == Dragged)
		{
			_state = Dragged;
			return onDragged(x);
		}
		else
		{
			return;
		}
	}
	else if(type == MouseUp)
	{
		if(_state == Pressed)
		{
			_state = Released;
			return onPressRelease(x);
		}
		else if(_state == Dragged)
		{
			_state = Released;
			return onDragRelease(x);
		}
	}
	return ;
}

VOID tmSlidingAnim::onPressed( int x )
{
	_timer.Reset();
	_speed  = 0;
	_position = 0;
	_moving = false;
	
}

VOID tmSlidingAnim::onDragged( int x )
{
	float dltTimePrev = (float) _timer.CalTicksElapsed()/_timer.GetTicksPerSecond();
	int		dltDist = x - _position;
	_position = x;
	_speed = ((float)dltDist) / dltTimePrev;
}

VOID tmSlidingAnim::onPressRelease( int x )
{
	_position = x;
}

VOID tmSlidingAnim::onDragRelease( int x )
{
	float dltTime = (float) _timer.CalTicksElapsed()/_timer.GetTicksPerSecond();
	if(dltTime > 0.1f)
	{
		_moving = false;
	}
	else
	{
		_moving = true;
		
	}
	_position = x;
}

float tmSlidingAnim::getMovingDistance()
{
	float dltTime = (float) _timer.CalTicksElapsed()/_timer.GetTicksPerSecond();
	return dltTime * _speed;
}